package Test;

/**
 * @BelongsProject: LeetCode
 * @BelongsPackage: Test
 * @Author: song
 * @CreateTime: 2024-09-05  10:39
 * @Description: TODO
 * @Version: 1.0
 */

public class SearchInsert {
    public int searchInsert(int[] nums, int target){
        int ans = nums.length;
        int left = 0;
        int right = nums.length;
        while (left < right){
            int middle = (left + right)/2;
            if (target <= nums[middle])
                ans =  middle;
            if (target > nums[middle])
                left = middle + 1;
            if (target < nums[middle])
                right = middle - 1;
        }
        return ans;
    }
}
